from flask import Flask, request, jsonify

import Baidu_Text_transAPI
import Translation
import test

app = Flask(__name__)


@app.route('/api/Tran', methods=['POST'])
def Tran():
    content = request.json.get('content')  # 获取请求数据
    from_lang = request.json.get('from_lang')
    tu_lang = request.json.get('tu_lang')
    print(from_lang)
    print(tu_lang)
    print(content)
    fan_text = ""
    if tu_lang["_value"] == "uy":
        zh_text = Translation.main(content["_value"])
        # uy_text = Translation.main(zh_text)
        # print(zh_text)
        fan_text = zh_text
    else:
        text = Baidu_Text_transAPI.FanBaidu(from_lang["_value"], tu_lang["_value"], content["_value"])
        # print(content["_value"])
        fan_text = text
    return jsonify({
        'message': f'{fan_text}'  # 返回处理结果
    })


@app.route('/api/chat', methods=['POST'])
def chat():
    content = request.json.get('content')  # 获取请求数据
    # 处理请求数据，例如：将内容存储到数据库，或者进行其他处理
    # ...
    text = test.Chat_Main(content["_value"])
    # print(content["_value"])
    return jsonify({
        'message': f'{text[1]["content"]}'  # 返回处理结果
})


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
